<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of Fd_mtx2</title>
  <meta name="keywords" content="Fd_mtx2">
  <meta name="description" content="Finite difference approximation of a 2D scalar diffusion equation in QTT">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">exp</a> &gt; Fd_mtx2.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/exp&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>Fd_mtx2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Finite difference approximation of a 2D scalar diffusion equation in QTT</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [mat]=Fd_mtx2(a) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Finite difference approximation of a 2D scalar diffusion equation in QTT
   [M]=FD_MTX(D, A, BOUND)
   Generate finite difference matrix from diffusion coefficient A(n,n) or A(n,n,n)
   M - n^D-by-n^D sparse matrix
   D - dimensions, 
   BOUND:
       0 - Dirichlet,
       1 - Neuman


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="../../tt2/@tt_tensor/size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/tests/test_cross3.html" class="code" title="">test_cross3</a>	</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [mat]=Fd_mtx2(a)</a>
0002 <span class="comment">%Finite difference approximation of a 2D scalar diffusion equation in QTT</span>
0003 <span class="comment">%   [M]=FD_MTX(D, A, BOUND)</span>
0004 <span class="comment">%   Generate finite difference matrix from diffusion coefficient A(n,n) or A(n,n,n)</span>
0005 <span class="comment">%   M - n^D-by-n^D sparse matrix</span>
0006 <span class="comment">%   D - dimensions,</span>
0007 <span class="comment">%   BOUND:</span>
0008 <span class="comment">%       0 - Dirichlet,</span>
0009 <span class="comment">%       1 - Neuman</span>
0010 <span class="comment">%</span>
0011 <span class="comment">%</span>
0012 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0013 <span class="comment">%</span>
0014 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0015 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0016 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0017 <span class="comment">%</span>
0018 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0019 <span class="comment">%ivan.oseledets@gmail.com</span>
0020 <span class="comment">%---------------------------</span>
0021 
0022 
0023 n=<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(a,1)-1; <span class="comment">%The coefficient is (n+1)x(n+1);</span>
0024 
0025 <span class="comment">%The solution is (n).^2, thus the matrix will be of this size</span>
0026 <span class="comment">%we need to create 4 arrays: up down left right</span>
0027 <span class="comment">%</span>
0028 <span class="comment">%</span>
0029 <span class="comment">%     |x y x |</span>
0030 <span class="comment">%      y O y</span>
0031 <span class="comment">%     |x y x |</span>
0032 <span class="comment">%</span>
0033 <span class="comment">%</span>
0034 
0035 <span class="comment">%the stencil is 5-point</span>
0036 
0037 ad=zeros(n,n);
0038   <span class="keyword">for</span> i=1:n-1
0039     <span class="keyword">for</span> j=1:n
0040        ad(i,j)=(a(i+1,j)+a(i+1,j+1))*0.5;
0041     <span class="keyword">end</span>
0042   <span class="keyword">end</span>
0043 au=zeros(n,n);
0044 au(2:n,1:n)=ad(1:n-1,1:n);
0045 <span class="comment">%for i=1:n-1</span>
0046 <span class="comment">%  for j=1:n</span>
0047 <span class="comment">%    au(i+1,j) = (a(i,j+1)+a(i+1,j+1))*0.5;</span>
0048 <span class="comment">%  end</span>
0049 <span class="comment">%end</span>
0050 <span class="comment">%au(2:n,1:n-1)=ad(1:n-1,1:n-1);</span>
0051 <span class="comment">%au=ad';</span>
0052 al=zeros(n,n);
0053  <span class="keyword">for</span> i=1:n
0054     <span class="keyword">for</span> j=1:n-1
0055        al(i,j)=(a(i,j+1)+a(i+1,j+1))*0.5;
0056     <span class="keyword">end</span>
0057  <span class="keyword">end</span>
0058   
0059 ar=zeros(n,n);
0060 <span class="comment">% for i=1:n</span>
0061 <span class="comment">%    for j=1:n</span>
0062 <span class="comment">%       ar(i,j)=(a(i+1,j)+a(i+1,j+1))*0.5;</span>
0063 <span class="comment">%    end</span>
0064 <span class="comment">%  end</span>
0065 <span class="comment">%ar(1:n-1,2:n)=al(1:n-1,1:n-1); %The matrix is symmetric</span>
0066 ar(1:n,2:n)=al(1:n,1:n-1);
0067 ac=zeros(n,n);
0068 <span class="keyword">for</span> i=1:n
0069   <span class="keyword">for</span> j=1:n
0070     ac(i,j)=(a(i,j)+a(i,j+1)+a(i+1,j)+a(i+1,j+1));
0071   <span class="keyword">end</span>
0072 <span class="keyword">end</span>
0073 <span class="comment">%2,4,3,1,5</span>
0074 <span class="comment">%d</span>
0075 <span class="comment">%u</span>
0076 <span class="comment">%c</span>
0077 <span class="comment">%l</span>
0078 <span class="comment">%r</span>
0079 bar_a=[-al(:), -ad(:), ac(:), -au(:), -ar(:)];
0080 mat = spdiags(bar_a, [-n, -1, 0, 1, n], n^2, n^2);
0081 mat=mat*(n+1).^2; <span class="comment">%Assumes [0,1]</span>
0082 
0083 <span class="keyword">return</span>
0084 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>